package com.fy56.platform.logistics.utils;

import sun.misc.BASE64Decoder;

import java.io.IOException;

/**
 * @author li
 * @date 2018-03-12 16:28
 */
public class UploadUtil {

    /**
     * 上传图片
     *
     * @param imgStr 图片字符串
     * @param imgName 图片名称
     * @return
     */
    public static String uploadPic(String url,String imgStr,String imgName){
        if (imgStr == null) {
            return null;
        }
        BASE64Decoder decoder = new BASE64Decoder();
        try {
            // 解密
            byte[] imagebyte = decoder.decodeBuffer(imgStr);
            // 处理数据
            for(int i = 0; i < imagebyte.length; ++i) {
                if (imagebyte[i] < 0) {
                    imagebyte[i] += 256;
                }
            }
            return HttpClientUtils.postMultipart(url,imagebyte,imgName,null,20000,20000);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
